package com.imooc.ecommerce.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 * 原生: swagger-ui.html
 * 美化: /doc.html
 * @Author: zhangshao
 * @Since: 2023/11/27 17:42
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

	/**
	 * swagger 实例 Bean是 Docket
	 * @return
	 */
	@Bean
	public Docket docket(){
		return new Docket(DocumentationType.SWAGGER_2)
				//展示在swagger页面上自定义工程的描述信息
				.apiInfo(apiInfo())
				//选择展示哪些接口
				.select()
				// 只有com.imooc.ecommerce包内的才去展示
				.apis(RequestHandlerSelectors.basePackage("com.imooc.ecommerce"))
				.paths(PathSelectors.any())
				.build();
	}

	/**
	 * 配置swagger描述信息
	 * @return
	 */
	public ApiInfo apiInfo(){
		return new ApiInfoBuilder()
				.title("imooc-micro-service")
				.description("e-commerce-springcloud-service")
				.contact(new Contact("Qinyi","www.imooc.com","dsssd@qq.com"))
				.version("1.0")
				.build();
	}
}
